package com.arges.web.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.arges.web.common.PropertiesUtils;
import com.arges.web.common.ResourceBundleUtils;

/**
 * 系统启动时加载配置文件
 * 
 * @author arges
 * 
 */
public class SystemInitListener implements ServletContextListener
{
	private static WebApplicationContext springContext;

	@Override
	public void contextDestroyed(ServletContextEvent event)
	{

	}

	@Override
	public void contextInitialized(ServletContextEvent event)
	{

		springContext = WebApplicationContextUtils.getWebApplicationContext(event.getServletContext());
		// 获取项目路径
		String configureFilePath = event.getServletContext().getRealPath("");
		// 加载配置文件
		PropertiesUtils.init(configureFilePath);
		// 加载国际化文件
		ResourceBundleUtils.init(configureFilePath);
	}

	public static ApplicationContext getApplicationContext()
	{
		return springContext;
	}
}
